package ru.acme.lab08.task3;

import java.lang.NumberFormatException;

class Task3 {
	public static Double avg(Integer[] array) {
		if (array.length == 0) {
			System.out.println("undefined value, array is empty");
			return null;
		}
		double avg = 0;
		for (int i = 0; i < array.length; ++i) {
			avg += array[i];
		}
        //zero case is checked in first line of method
		avg /= array.length;
		return avg;
	}
	
	public static void main(String[] argv) {
		Integer n = 50;
		if (argv.length >= 1) {
			try {
				n = Integer.parseInt(argv[0]);
			} catch (NumberFormatException e) {
				System.out.println("Bad argument");
				return;		
			}
		}
		Integer[] array = new Integer[n];
		for (int i = 0; i < n; ++i) {
			array[i] = i + 1;
		}
		for (int i = 0; i < n; ++i) {
			String message;
			if (array[i] % 3 == 0) {
				message = "Number " + array[i] + " is dibidible by 3";
			} else {
				message = array[i].toString();
			}
			System.out.println(message);
		}
		System.out.println("average = " + avg(array));
	}
}